package net.maku.module.business.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.module.business.entity.DictionariesEntity;
import net.maku.module.business.service.DictionariesService;
import net.maku.module.business.vo.DictionariesVO;
import net.maku.newbase.*;
import net.maku.newbase.annotation.result.RDataToVO;
import net.maku.newbase.annotation.result.RDataType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 业务_字典
 *
 * @author
 */
@RestController
@RequestMapping("nb/business/dictionaries")
@Tag(name = "业务_字典")
@AllArgsConstructor
public class DictionariesController extends NewBaseController<DictionariesService, DictionariesEntity> {

    @Autowired
    protected DictionariesService dictionariesService;

    /**
     * 分页
     *
     * @param page
     * @param query
     * @return
     */
    @Operation(summary = "分页")
    @RequestMapping(value = "page", method = RequestMethod.GET)
    public R page(PageParam page, NewQuery query) {
        LambdaQueryWrapper<DictionariesEntity> select = new LambdaQueryWrapper<>();

        IPage<DictionariesEntity> iPage = entityService.page(page.b(), select);
        return R.ok(new PageResult<>(iPage.getRecords(), iPage.getTotal()));
    }

    @Operation(summary = "查询 code")
    @RDataToVO(type = RDataType.ENTITY, c = DictionariesVO.class)
    @RequestMapping(value = "findByCode", method = RequestMethod.GET)
    public R findByCode(String code) {
        return R.ok(dictionariesService.findByCode(code));
    }

}